<template>
  <div class="dashboard">
    <el-row :gutter="20">
      <el-col :span="8">
        <el-card class="box-card">
          <template #header>
            <div class="card-header">
              <span>Operating System</span>
            </div>
          </template>
          <div class="text item">
            {{ systemInfo.operatingSystem }}
          </div>
        </el-card>
      </el-col>

      <el-col :span="8">
        <el-card class="box-card">
          <template #header>
            <div class="card-header">
              <span>Processor</span>
            </div>
          </template>
          <div class="text item">
            <div>{{ systemInfo.processor.split('\n')[0] }}</div>
            <div>{{ systemInfo.processor.split('\n')[1] }}</div>
            <div>{{ systemInfo.processor.split('\n')[2] }}</div>
            <div>{{ systemInfo.processor.split('\n')[3] }}</div>
          </div>
        </el-card>
      </el-col>

      <el-col :span="8">
        <el-card class="box-card">
          <template #header>
            <div class="card-header">
              <span>Memory</span>
            </div>
          </template>
          <div class="text item">
            {{ systemInfo.memory }}
          </div>
        </el-card>
      </el-col>
    </el-row>
  </div>
</template>

<script setup>
import { ref, onBeforeMount } from 'vue'
import { request } from '@/utils/request'

const systemInfo = ref({
  operatingSystem: '',
  processor: '',
  memory: '',
})

const requestSystemInfo = async () => {
  try {
    const response = await request.get('/api/systemInfo')
    systemInfo.value = response
  } catch (error) {
    console.error('Error fetching system info:', error)
  }
}

onBeforeMount(() => {
  requestSystemInfo()
})
</script>

<style scoped>
.dashboard {
  width: 100%;
}

.box-card {
  width: 100%;
  margin: 20px 0;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.text {
  font-size: 14px;
}

.item {
  margin-bottom: 18px;
}

.clearfix:before,
.clearfix:after {
  display: table;
  content: '';
}

.clearfix:after {
  clear: both;
}
</style>
